package org.hank.wanandroid.ui

import android.os.Bundle
import org.hank.commom.base.BaseActivity
import org.hank.commom.listener.ReloadListener
import org.hank.wanandroid.R
import org.hank.wanandroid.bean.PageArticleBean
import org.hank.wanandroid.listener.OnArticleRecyclerListener
import org.hank.wanandroid.ui.widget.ArticleRecycleWidget
import org.hank.wanandroid.viewmodel.HomePageViewModel

class TestActivity : BaseActivity(),ReloadListener,OnArticleRecyclerListener{
    var articleRecyclerFragment = ArticleRecycleWidget(this)
    lateinit var curPage: PageArticleBean
    var CurPage = 0

    private val homePageViewModel by getViewModel(HomePageViewModel::class.java) {
        articleLive.observe(it) {
            validateArticle(it)
        }
    }
    override val layoutResId: Int
        get() =R.layout.activity_test

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var ft = supportFragmentManager.beginTransaction()
        ft.add(R.id.fram_test, articleRecyclerFragment)
        ft.commit()
    }

    override fun onResume() {
        super.onResume()
        getData()
    }
    fun validateArticle(pageArticleBean: PageArticleBean) {
        this.curPage = pageArticleBean
        articleRecyclerFragment.validateData(pageArticleBean.datas)
    }

    fun getData() {
        homePageViewModel.getArticle(CurPage)
    }

    override fun reload() {

    }

    override fun onReload() {

    }
}